public class ArrayStack {
    int top;
    int capacity;
    int[] array;

    public ArrayStack(int capacity){
        this.capacity = capacity;
        array = new int[capacity];
        top = -1;
    }

    /**
     * 判断栈是否为空
     * @return 栈为空时返回1，否则为0
     */
    boolean isStackEmpty(){
        //栈为空时返回1，否则为0
        return (top == -1);
    }

    /**
     * 判断栈是否满了
     * @return 栈满时返回1，否则为0
     */
    boolean isStackFull(){
        //栈满时返回1，否则为0
        return (top == capacity - 1);
    }

    /**
     * 压栈操作
     * @param data:压入栈中数据
     */
    void push(int data){
        if(!isStackFull()){
            array[++top] = data;
            System.out.println("the "+data+" is push");
        } else{
            System.out.println("栈已满");
        }
    }

    /**
     * 出栈操作
     * @return 返回栈顶数据
     */
    int pop(){
        if(!isStackEmpty()){
            return (array[top--]);
        }else{
            System.out.println("栈为空");
            return 0;
        }
    }

    /**
     * 删除整个栈
     */
    void deleteStack(){
        top = -1;
    }
}

class ArrayStackTest{
    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack(5);
        for (int i=0;i<5;i++){
            arrayStack.push(i+1);
        }
        arrayStack.push(6);
        for (int i=0;i<5;i++){
            System.out.println("the "+arrayStack.pop()+" is pop");
        }
        arrayStack.push(6);
        System.out.println(arrayStack.pop());
    }
}
